﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class frmThaydoimatkhau : Form
    {
        public frmThaydoimatkhau()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            frmThaydoimatkhau frmtdmk = new frmThaydoimatkhau();
            frmtdmk.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtPasscu.Text == "" || txtPassmoi1.Text == "" || txtPassmoi2.Text == "")

                MessageBox.Show("Vui lòng nhập đầy đủ mật khẩu!", "Report", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            else
            {
                if (txtPassmoi1.Text != txtPassmoi2.Text)
                {
                    MessageBox.Show("Bạn đã nhập sai mật khẩu cũ", "Report", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    string str1 = lblUser.Text;
                    string str2 = txtPassmoi1.Text;
                    ChangePass(str1, str2);
                    MessageBox.Show("Đổi mật khẩu thành công!", "Hệ thống quản lý sinh viên");
                }
            }
        }
        public void ChangePass(String str1, String str2)
        {
            RibbonForm1 rb = new RibbonForm1();
            SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=SM;Integrated Security=True");
            SqlCommand cmd;
            cmd = new SqlCommand();
            cmd.CommandText = "ChangePass";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = connection;
            connection.Open();
            cmd.Parameters.AddWithValue("@Username", lblUser.Text);
            cmd.Parameters.AddWithValue("@Password", txtPassmoi1.Text);
            cmd.ExecuteNonQuery();
            connection.Close();
        }
    }
}
